Repository navigation
Close pull requests opened from a fork - #205
Merged
Merged
Conversation
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
.github/workflows/close-fork-prs.yml, which closes pull requests opened from a fork and explains to the author what to do instead. Contributors have started picking up tickets without joining the DevOps group, and a fork PR onincubatorordevops-securitycan never be merged —terraform plancan't run, so there is nothing to review. Leaving those PRs open just wastes the contributor's time.The same file goes in all three CoP repos (
devops,devops-security,incubator), byte-identical.Two ways it runs:
pull_request_target(opened,reopened) — closes the PR straight away with a comment.workflow_dispatch) — sweeps every open pull request in the repo and closes the ones from forks. Defaults to a dry run that lists what it would close and closes nothing, so the destructive version is always a deliberate choice.The check is one expression: a PR is from a fork exactly when
head.repo.full_name != github.repository.Why
pull_request_targetand notpull_request: apull_requestrun triggered from a fork gets a read-onlyGITHUB_TOKENand cannot close or comment on anything — the same restriction that makes fork PRs unmergeable in the first place.pull_request_targetruns with the base repo's token.Security.
pull_request_targetis the trigger with the privilege-escalation footgun, so the workflow deliberately: checks out nothing, builds nothing, uses no third-party actions at all (just the preinstalledghCLI), and passes every PR-controlled value through the environment rather than interpolating it into a shell command. There is no path for code or text from the pull request to be executed. Permissions arecontents: readandpull-requests: write.No actions to pin means nothing here to version-bump later.
Note on sequencing:
workflow_dispatchonly appears in the Actions tab once this is on the default branch — GitHub reads both triggers from there. The comment it posts links to the "Do not fork the repository" section added in #204, so that one should merge first.